package cn.jsj.dispose;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jsj.object.FrontAdminInfo;
import cn.jsj.pojo.TblAdminPersonnel;
import cn.jsj.utils.ProduceJsonData;
import cn.jsj.utils.SysLogger;
/**
 * 加载所有的行政人员信息处理类
 * @author LI
 *
 */
 public class AdminPersonInfoRequest extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("加载所有行政人员信息");
		//获得参数：1.第几条开始。2.一页显示几条
		int startNumb=Integer.parseInt(request.getParameter("start"));
		int totalNumb=Integer.parseInt(request.getParameter("limit"));

		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("start---->"+startNumb+"   total--------->"+totalNumb);

		//获得总共行政人员信息数
		cn.jsj.dao.TblAdminPersonnelDAO tapd=new cn.jsj.dao.TblAdminPersonnelDAO();
		int adminInfoNumber=tapd.getAdminInfoNumb();

		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("行政人员信息条数----->"+adminInfoNumber);

		//暂存行政人员信息队列
		java.util.List<TblAdminPersonnel> adminList=new java.util.LinkedList<TblAdminPersonnel>();

		//获得这个页面要显示的行政人员信息
		adminList=tapd.getTheAdminInfo(startNumb, totalNumb);

		//调试信息
		SysLogger.PrintInfo(adminList.size());

		//前台行政人员信息对象队列
		java.util.List<FrontAdminInfo> frontAdminInfo=new java.util.LinkedList<FrontAdminInfo>();
		//改造成前台需要的行政人员信息对象
		cn.jsj.object.rebuild.AdminInfoRebuild air=new cn.jsj.object.rebuild.AdminInfoRebuild();
		for(int i=0;i<adminList.size();i++){
			cn.jsj.object.FrontAdminInfo fai=air.rebuildAdmin(adminList.get(i));
			frontAdminInfo.add(fai);
		}

		//改造成JSON型数据
		ProduceJsonData pjd=new ProduceJsonData();
		String resultData=	pjd.jsonFromList(frontAdminInfo,adminInfoNumber);

		//调试信息
		SysLogger.PrintInfo(resultData);
		//输出到客户端
		java.io.PrintWriter pw=response.getWriter();
		pw.println(resultData);
		pw.flush();
		pw.close();

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}
}